home *** CD-ROM | disk | FTP | other *** search
- Path: newsfeed.tip.net!dataphone!newsmaster
- From: skorpio@dataphone.se (Jarmo Paavilainen)
- Newsgroups: comp.lang.c
- Subject: Re: Can a function return a (pointer to a) function?
- Date: 27 Jan 1996 17:50:22 GMT
- Organization: Dataphone Communication Networks
- Message-ID: <4edoku$ljk@nic.dataphone.se>
- NNTP-Posting-Host: nikson.dataphone.se
- X-Newsreader: NeoLogic News for OS/2 [version: 4.2]
-
- In message <4ebaaa$jh6@barnacle.iol.ie> - "John D. Hourihane" <hourihaj@iol.ie>
- writes:
-
- Im not sure but try this :
- #include <stdio.h>
-
- #define ADD 0
- #define MULTIPLY 1
-
- int add(int x, int y);
- int multiply(int x, int y);
-
- (int (*)(int,int)) pick(int s);
-
- int main()
- {
- void (*func)(int,int);
-
- func = pick(ADD);
- printf("5 + 4 = %d\n",func(5,4));
- func = pick(MULTIPLY);
- printf("5 * 4 = %d\n",func(5,4));
- return 0;
- }
-
- int add(int x, int y)
- { return x + y; }
-
- int multiply(int x, int y)
- { return x * y; }
-
- (int (*)(int,int)) pick(int s)
- {
- if (s == ADD)
- return add;
- return multiply;
- }
-
- As I wrote, Im not sure, if this will work !
-
- Take care,
- Skorpio
- _________________________________________________________________________
- Jarmo Paavilainen, Skorpio | e-mail : skorpio@dataphone.se
- Sweden | home : http://www.dataphone.se/~skorpio
-
- Spelling ? I don't need no stinking spelling !
-
-
-